/***************************************************************************
 *   Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN  *
 *   {prenom.nom}_at_lip6.fr                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
/** @file
 * @brief class repesent a node containing a vector of Unsigned Int 
 *
 * @author Maroua HAMMAMI and Malak HAMZEH
 *
 */
#include<agrum/learning/database.h>
#include<agrum/learning/InstantiationBoxTools.h>
#include <agrum/core/inline.h>

namespace gum {

using namespace std;

class CountTree{
private: 
		const Database &__database;
		InstantiationBox *__root; // The root of the tree
		List<const InstantiationBox *> __leaves; // List contains all the Nijk
		vector<unsigned int> __variables; // variables manipulating in the tree
		vector<ListBase<InstantiationBox *> *> __levels;//vector containing all listBases in the level N-2
public:
		CountTree(const Database &database);//Constructor
		void clear(); // clear levels, root and leaves
		void eraseLastParent(); //Erase last parent 
		void addParent(unsigned int parent); //Add a parent to the countTree
		List<const InstantiationBox *>& count();
		void setVariables(vector<unsigned int> variables);
		void replaceParent(unsigned int oldParent, unsigned int newParent);
		unsigned int findParent(unsigned int parent);
		void eraseParent(unsigned int position);

protected:	
		void updateLeaves(InstantiationBox &child);
		void updateLevels(InstantiationBox &parent, unsigned int nbrParent);
		void setLeaves(ListBase<InstantiationBox *> &parents);


};//End of class CountTree

}//End of namespace gum

#ifndef GUM_NO_INLINE
#include <agrum/learning/CountTree.inl>
#endif /* GUM_NO_INLINE */

